//
//  CustomTableViewCell.m
//  电影
//
//  Created by dllo on 16/6/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomTableViewCell.h"
#import "MovieModel.h"

#define kWith self.contentView.frame.size.width
#define kHeight self.contentView.frame.size.height

@interface CustomTableViewCell()

@property (nonatomic, retain) UIImageView *movieImageView;

@property (nonatomic, retain) UILabel *nameLabel;

@property (nonatomic, retain) UILabel *idLabel;

@end

@implementation CustomTableViewCell

-(void)dealloc
{
    [_cellModel release];
    [_movieImageView release];
    [_nameLabel release];
    [_idLabel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.backgroundColor = [UIColor colorWithRed:0.99 green:0.92 blue:0.94 alpha:1.0];
        
        self.nameLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.nameLabel];
        [self.nameLabel release];
        
        self.idLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.idLabel];
        [self.idLabel release];
        
        self.movieImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:self.movieImageView];
        [self.movieImageView release];
        
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.movieImageView.frame = CGRectMake(10, 10, kWith * 0.3, kHeight - 20);
    self.movieImageView.backgroundColor = [UIColor redColor];
    
    self.nameLabel.frame = CGRectMake(_movieImageView.frame.size.width + 40, 20, kWith * 0.5, kHeight * 0.2);
    
    self.idLabel.frame = CGRectMake(_nameLabel.frame.origin.x, kHeight * 0.2 + 40, kWith * 0.5, kHeight * 0.2);
}

-(void)setCellModel:(MovieModel *)cellModel
{
    if (_cellModel != cellModel) {
        [_cellModel release];
        _cellModel = [cellModel retain];
    }
    
    
    NSURL *url = [NSURL URLWithString:cellModel.pic_url];
    
    NSData *data = [NSData dataWithContentsOfURL:url];
    
    UIImage *image = [UIImage imageWithData:data];
    
    self.movieImageView.image = image;
    self.nameLabel.text = cellModel.movieName;
    self.idLabel.text = cellModel.movieId;
    
    
}



@end


















